﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Lib.Utils;

namespace MS.INV.Reports.Qtys
{
    public partial class Item : UserControl
    {
        public event EventHandler OnRefresh;
        public event EventHandler OnPrint;

        DataTable DT = new DataTable();

        public int IdHangHoa { get { return Cvert.ToInt32(cboHH.EditValue, 0); } }

        public Item()
        {
            InitializeComponent();
        }

        public void OnLoad()
        {
            using (SysObj.L_HangHoa hh = new SysObj.L_HangHoa())
            {
                DT = hh.LoadData();
                cboHH.Properties.SetDataSource(DT, "MaHang,TenHang#Mã,Tên");
            }
        }

        private void cboHH_EditValueChanged(object sender, EventArgs e)
        {
            DataRow[] rS = DT.Select("IdHangHoa=" + Cvert.ToInt32(cboHH.EditValue, 0));
            if (!object.Equals(rS, null) && rS.Length > 0)
            {
                txtMa.Text = rS[0]["MaHang"].ToString();
                txtDVT.Text = Cvert.ToString(rS[0]["TenDVT"], "");
                txtLoai.Text = Cvert.ToString(rS[0]["TenLoai"], "");
                txtNhom.Text = Cvert.ToString(rS[0]["TenNhom"], "");
            }
        }

        private void btRef_Click(object sender, EventArgs e)
        {
            if (OnRefresh != null)
                OnRefresh(btRef, e);
        }

        private void btPrint_Click(object sender, EventArgs e)
        {
            if (OnPrint != null)
                OnPrint(btPrint, e);
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            Form f = this.FindForm();
            if (!object.Equals(f, null))
                f.Close();
        }
    }
}
